package com.lanou.fooddemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.lanou.fooddemo.R;
import com.lanou.fooddemo.theme.FoodTheme;
import com.lanou.fooddemo.util.CommonUtil;
import com.lanou.fooddemo.view.FoodToast;

public class ThemeListActivity extends Activity implements View.OnClickListener{
    /**
     * 红色主题item布局
     */
    private LinearLayout themeListRedTheme;
    /**
     * 蓝色主题item布局
     */
    private LinearLayout themeListBlueTheme;
    /**
     * 标题布局
     */
    private RelativeLayout headerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_theme_list);

        initView();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        themeListRedTheme = (LinearLayout) findViewById(R.id.themeListRedTheme);
        themeListBlueTheme = (LinearLayout) findViewById(R.id.themeListBlueTheme);
        headerLayout = (RelativeLayout) findViewById(R.id.headerLayout);

        //设置红色主题item点击事件
        themeListRedTheme.setOnClickListener(this);
        //设置蓝色主题item点击事件
        themeListBlueTheme.setOnClickListener(this);
        //设置主题
        setFoodActivityTheme();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.themeListRedTheme :
                if (FoodTheme.TYPE_RED.equals(FoodTheme.getCurrentTheme())) {
                    FoodToast.makeText(ThemeListActivity.this,
                            "已经是这个主题啦，不需要再选了呦", FoodToast.LENGTH_SHORT).show();
                } else {
                    //设置红色主题
                    CommonUtil.setFoodThemeRed(ThemeListActivity.this);
                    //设置主题适应改变
                    setFoodActivityTheme();
                    FoodToast.makeText(ThemeListActivity.this,
                            "主题设置成功", FoodToast.LENGTH_SHORT).show();
                }
                break;
            case R.id.themeListBlueTheme :
                if (FoodTheme.TYPE_BLUE.equals(FoodTheme.getCurrentTheme())) {
                    FoodToast.makeText(ThemeListActivity.this,
                            "已经是这个主题啦，不需要再选了呦", FoodToast.LENGTH_SHORT).show();
                } else {
                    //设置蓝色主题
                    CommonUtil.setFoodThemeBlue(ThemeListActivity.this);
                    //设置主题适应改变
                    setFoodActivityTheme();
                    FoodToast.makeText(ThemeListActivity.this,
                            "主题设置成功", FoodToast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    /**
     * 设置主题
     */
    public void setFoodActivityTheme() {
        //设置标题背景颜色
        headerLayout.setBackgroundResource(FoodTheme.getHeaderLayoutColor());
    }
}
